# Contributor: nibon7 <nibon7@163.com>
# Maintainer: nibon7 <nibon7@163.com>
pkgname=nushell
pkgver=0.65.0
pkgrel=0
pkgdesc="A new type of shell"
url="https://www.nushell.sh"
# s390x/riscv64 rust/cargo
arch="x86_64 armv7 armhf aarch64 x86 ppc64le"
license="MIT"
makedepends="cargo pkgconf openssl-dev libx11-dev libxcb-dev libgit2-dev"
subpackages="$pkgname-plugins:_plugins"
install="$pkgname.post-install $pkgname.post-upgrade $pkgname.pre-deinstall"
source="$pkgname-$pkgver.tar.gz::https://github.com/nushell/nushell/archive/$pkgver.tar.gz"

# Reduce size of nu binary from 22.7 -> 13.8 MiB (on x86_64 with default feature).
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_LTO="fat"
export CARGO_PROFILE_RELEASE_OPT_LEVEL="s"
export CARGO_PROFILE_RELEASE_PANIC="abort"

prepare() {
	default_prepare
	cargo fetch --locked
}

build() {
	cargo build --workspace --release --frozen
}

check() {
	cargo test --workspace --frozen
}

package() {
	find target/release \
		-maxdepth 1 \
		-executable \
		-type f \
		-name "nu*" \
		-exec install -Dm755 '{}' -t "$pkgdir"/usr/bin/ \;
}

_plugins() {
	pkgdesc="Nushell plugins"
	depends="nushell"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/nu_plugin_* "$subpkgdir"/usr/bin/
}

sha512sums="
007a3351d1a2f18bb1f4b0bc8e97abf4b9f58f566eae202355263e176acf331037687205b221ce4c8185ef1f44d5081d10d04de20823d61a6c14595205439ac9  nushell-0.65.0.tar.gz
"
